<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Orders extends Migrator
{
    public function up()
    {
        $table = $this->table('orders', array('comment' => '订单表'));
        $table->addColumn('number', 'string', array('limit' => 20, 'comment' => '订单编号'))
              ->addColumn('order_user_id', 'integer', array('comment' => '订单用户ID'))
              ->addColumn('rent_contact_id', 'string', array('limit' => 255, 'comment' => '订单联系人id', 'null'=>true))
              ->addColumn('stage', 'integer', array('limit' => 2, 'default' => 0, 'comment' => '订单阶段'))
              ->addColumn('status', 'integer', array('limit' => 2, 'default' => 0, 'comment' => '订单状态'))
              ->addColumn('caravan_id', 'integer', array('limit' => 5, 'comment' => '房车ID'))
              ->addColumn('caravan_user_id', 'integer', array('limit' => 5, 'comment' => '房车拥有者ID'))  
              ->addColumn('camp_id', 'integer', array('limit' => 3, 'comment' => '营地ID'))
              ->addColumn('service_fee', 'integer', array('limit' => 5, 'default' => 0, 'comment' => '服务费'))
              ->addColumn('travel_coin', 'integer', array('limit' => 10, 'default' => 0, 'comment' => '花费旅行币'))
              ->addColumn('total_money', 'integer', array('limit' => 10, 'default' => 0, 'comment' => '出租消费钱数'))
              ->addColumn('take_car_area', 'string', array('limit' => 255, 'comment' => '取车地点'))
              ->addColumn('leave_car_area', 'string', array('limit' => 255, 'comment' => '还车地点'))
              ->addColumn('take_car_date', 'date', array('comment' => '取车时间'))
              ->addColumn('leave_car_date', 'date', array('comment' => '还车时间'))
              ->addColumn('paid_at', 'timestamp', array('null' => true, 'comment' => '支付时间'))
              ->addColumn('created_at', 'timestamp', array('default' => 'CURRENT_TIMESTAMP'))
              ->addColumn('updated_at', 'timestamp', array('null' => true))
              ->addIndex('id')
              ->addIndex('order_user_id')
              ->addIndex('caravan_id')
              ->addIndex('caravan_user_id')
              ->addIndex('camp_id')
              ->save();   
    }
    public function down()
    {
        $this->dropTable('orders');
    }
}
